import { ElMessage, ElMessageBox, ElNotification, ElLoading } from "element-plus"
import type { LoadingOptions, ElMessageBoxOptions, NotificationParams } from "element-plus"
import type { LoadingInstance } from "element-plus/lib/components/loading/src/loading.js"

type messageType = "error" | "info" | "success" | "warning"

/** 信息提示 */
export const bsMessage = (message: string, type: messageType = "info") =>
  ElMessage({
    message,
    type
  })

type messageBoxType = "alert" | "prompt" | "confirm"

/** 信息弹出框 */
export const bxMessageBox = async (message: string, options: ElMessageBoxOptions, type: messageBoxType = "confirm") => {
  return await ElMessageBox[type](message, options)
}

type notifiyType = "success" | "warning" | "info" | "error"

/** 通知信息 */
export const bsNotifiy = (options: NotificationParams, type: notifiyType = "info") => ElNotification[type](options)

const loading = (options?: LoadingOptions): LoadingInstance => {
  const defaultOptions = {
    lock: true,
    text: "加载中...",
    body: true,
    ...options
  }
  return ElLoading.service(defaultOptions)
}

export { loading, LoadingOptions, LoadingInstance }
